package com.by.facade.enums.order;

import com.by.toolkit.enums.FlagEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Getter
@AllArgsConstructor
public enum OrderPayMehtodEnum {

    ZERO_PAY(1, "0元支付", null, null, FlagEnum.NO.getCode(), FlagEnum.NO.getCode()),
    SYS_PAY(2, "系统支付", null, null, FlagEnum.NO.getCode(), FlagEnum.NO.getCode()),
    WX_JSAPI(3, "微信jsapi", OrderThirdpartyTypeEnum.WX, RefundOrderPlatformEnum.WX, FlagEnum.YES.getCode(), FlagEnum.NO.getCode()),
    WX_H5(4, "微信H5", OrderThirdpartyTypeEnum.WX, RefundOrderPlatformEnum.WX, FlagEnum.YES.getCode(), FlagEnum.NO.getCode()),
    ALIPAY_H5(5, "支付宝H5", OrderThirdpartyTypeEnum.ALIPAY, RefundOrderPlatformEnum.ALI, FlagEnum.YES.getCode(), FlagEnum.NO.getCode()),
    CORP_ACCOUNT(6, "对公账户打款", OrderThirdpartyTypeEnum.CORP_ACCOUNT, null, FlagEnum.YES.getCode(), FlagEnum.YES.getCode()),
    WX_CP_MCH(7, "企微商户", null, null, FlagEnum.YES.getCode(), FlagEnum.YES.getCode()),
    WX_SCAN(8, "微信扫码", null, null, FlagEnum.YES.getCode(), FlagEnum.YES.getCode()),
    ALI_SCAN(9, "支付宝扫码", null, null, FlagEnum.YES.getCode(), FlagEnum.YES.getCode()),
    ;

    private Integer code;
    private String desc;

    private OrderThirdpartyTypeEnum thirdpartyTypeEnum;
    private RefundOrderPlatformEnum orderRefundPlatformEnum;

    private Integer achievement;
    // 是否线下收款
    private Integer offlinePayFlag;

    private static final Map<Integer, OrderPayMehtodEnum> MAP = Arrays.stream(OrderPayMehtodEnum.values())
            .collect(Collectors.toMap(OrderPayMehtodEnum::getCode, Function.identity()));


    public static OrderPayMehtodEnum resolve(Integer code) {
        return MAP.get(code);
    }

    public static final int ZERO_PAY_CODE = 1;
    public static final int SYS_PAY_CODE = 2;
    public static final int WX_JSAPI_CODE = 3;
    public static final int WX_H5_CODE = 4;
    public static final int ALIPAY_H5_CODE = 5;
    public static final int CORP_ACCOUNT_CODE = 6;
    public static final int WX_CP_MCH_CODE = 7;
    public static final int WX_SCAN_CODE = 8;
    public static final int ALI_SCAN_CODE = 9;

    public static List<Integer> getWxMethod() {
        return List.of(OrderPayMehtodEnum.WX_JSAPI_CODE, OrderPayMehtodEnum.WX_H5_CODE);
    }

}
